package leetcode_601_700;

import node.TreeNode;

public class LeeCode_606 {
    public static void main(String[] args) {

    }
    private static String tree2str(TreeNode root) {
        String ans = dfs(root);
        return ans.substring(1, ans.length() - 1);
    }
    private static String dfs(TreeNode node){
        if (node == null){
            return "";
        }
        String l = dfs(node.left);
        String r = dfs(node.right);
        if (l.length() == 0 && r.length() != 0){
            l = "()";
        }
        return "(" + node.val + l + r + ")";
    }
}
